/*************************************************************************
> File Name: test_03.cpp
> Author: hzy
> Created Time: 2023-08-15 16:51:54
> Description: 访问虚函数地址表（虚函数表是一个指向虚函数的函数指针数组）
************************************************************************/
#include <iostream>

using namespace std;

class Base
{
private:
    int val;

public:
    virtual void show1();
    virtual void show2();
    virtual void show3();
};

void Base::show1()
{
    cout << "Base:show1()" << endl;
}

void Base::show2()
{
    cout << "Base:show2()" << endl;
}

void Base::show3()
{
    cout << "Base:show3()" << endl;
}

class Son : public Base
{
public:
    void show2();
    void show3();
};

void Son::show2()
{
    cout << "Son:show2()" << endl;
}

void Son::show3()
{
    cout << "Son:show3()" << endl;
}

typedef void (*FUNC_P)();

int main()
{
    Son son;

    long *p = (long *)&son;
    //long v_table = *p;
    //long *arr_p = (long *)v_table;
    long *arr_p =(long *)*p;
    for (int i = 0; i < 3; i++)
    {
        ((FUNC_P)(*(arr_p + i)))();
    }

    return 0;
}